#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
class Solution
{
public:
    vector<int> platesBetweenCandles(string s, vector<vector<int>> &queries)
    {
        vector<int> ans(queries.size(), 0);
        // left,right表示第i处左右的第一个蜡烛处
        vector<int> preSum(s.size(), 0), left(s.size(), 0), right(s.size(), 0);
        int flag = 0, cnt = 0;
        for (int i = 0; i < s.size(); i++) //处理前缀和
        {
            if (flag == 0 && s[i] == '|')
                flag = 1;
            else if (flag == 1)
            {
                if (s[i] == '*')
                {
                    cnt++;
                    preSum[i] = preSum[i - 1];
                }
                else if (s[i] == '|')
                {
                    preSum[i] = cnt;
                }
            }
        }
        for (int i = 0; i < s.size(); i++) //处理左方向第一个蜡烛
        {
            if (s[i] == '|')
                left[i] = i;
            else if (i >= 1 && s[i] == '*')
                left[i] = left[i - 1];
        }
        for (int i = s.size() - 1; i >= 0; i--) //处理右方向第一个蜡烛
        {
            if (s[i] == '|')
                right[i] = i;
            else if (i < s.size() - 1 && s[i] == '*')
                right[i] = right[i + 1];
        }
        int l = 0, r = 0;
        for (int i = 0; i < queries.size(); i++)
        {
            l = queries[i][0], r = queries[i][1];
            if (l != r && left[r] >= right[l])
                ans[i] = preSum[left[r]] - preSum[right[l]];
        }
        // for (int i = 0; i < preSum.size(); i++)
        // {
        //     cout << preSum[i] << endl;
        // }
        return ans;
    }
};
int main()
{
    Solution *s = new Solution();
    // vector<vector<int>> queries{{1, 17}, {4, 5}, {14, 17}, {5, 11}, {15, 16}};
    vector<vector<int>> queries{{3, 3}};
    vector<int> ans = s->platesBetweenCandles("|*|*", queries);
    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << endl;
    }
    return 0;
}